/*
 * F4.c
 *
 *  Created on: 21/10/2012
 *      Author: Sarah
 */

#include "F4.h"

double F4minX = -100;
double F4maxX = 100;
int F4dimensions = 1000;
int nonSeparableGroupSize = 50;
double F4Compute(double* x) {
	double result;
	int i;

	double* F4Ovector = createShiftVector(F4dimensions,F4minX, F4maxX);
	double* F4anotherz = malloc(sizeof(double) * F4dimensions);
	double* F4anotherz1 = malloc(sizeof(double) * F4dimensions);
	double* F4anotherz2 = malloc(sizeof(double) * F4dimensions);
	int* Pvector=createPermVector(F4dimensions);

	double *lookup = lookupprepare(F4dimensions - nonSeparableGroupSize);

	F4Ovector = createShiftVector(F4dimensions, F4minX, F4maxX);

	double *RotMatrix = createRotMatrix1D(nonSeparableGroupSize);

	for (i = 0; i < F4dimensions; i++) {
		F4anotherz[i] = x[i] - F4Ovector[i];
	}

	for (i = 0; i < nonSeparableGroupSize; i++) {
		F4anotherz1[i] = F4anotherz[Pvector[i]];
	}

	for (i = nonSeparableGroupSize; i < F4dimensions; i++) {
		F4anotherz2[i - nonSeparableGroupSize] = F4anotherz[Pvector[i]];
	}

	result = rot_elliptic(F4anotherz1, nonSeparableGroupSize) * 1e6
			+ elliptic(F4anotherz2, F4dimensions - nonSeparableGroupSize, lookup);


	return (result);

	free(F4Ovector);
	free(F4anotherz);
	free(F4anotherz1);
	free(F4anotherz2);
	free(lookup);
	free(Pvector);

	return (result);
}

int F4GetDimensions() {
	return F4dimensions;
}
double F4GetGetMax() {
	return F4maxX;
}
double F4GetMin() {
	return F4minX;
}
